<?php

namespace zhtfrontend\models\datas;

use common\components\extenders\MenuManage;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "{{%full_activities}}".
 *
 * @property integer $id
 * @property string $name
 * @property integer $type
 * @property string $money
 * @property string $give_money
 * @property integer $start_time
 * @property integer $end_time
 * @property integer $number
 * @property integer $created_at
 */
class FullActivities extends \zhtfrontend\components\bases\BaseModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%full_activities}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['type', 'number', 'created_at','status'], 'integer'],
            [['money', 'give_money'], 'number'],
            [['name'], 'string', 'max' => 100],
            [['name','type','money','give_money','start_time','end_time','number','status'],'required'],
        ];
    }

    public function fields(){
        $fields = parent::fields();
        $fields['type'] = function (){
            switch ($this->type){
                case 1:
                    return \Yii::t('zhtfrontend','益智');
                case 2:
                    return \Yii::t('zhtfrontend','音乐');
                case 3:
                    return \Yii::t('zhtfrontend','形体');
            }
        };
        $fields['start_time'] = function (){
            return date('Y-m-d H:i',$this->start_time);
        };
        $fields['end_time'] = function (){
            return date('Y-m-d H:i',$this->end_time);
        };

        $fields['created_at'] = function (){
            return \Yii::$app->formatter->asDatetime($this->created_at);
        };
        $fields['status'] = function (){
            switch ($this->status){
                case 1:
                    return \Yii::t('zhtfrontend','启用');
                case 2:
                    return \Yii::t('zhtfrontend','禁用');
            }
        };

        return $fields;
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('zhtfrontend', '自增id'),
            'name' => Yii::t('zhtfrontend', '满增名称'),
            'type' => Yii::t('zhtfrontend', '三大类'),
            'money' => Yii::t('zhtfrontend', '满额'),
            'give_money' => Yii::t('zhtfrontend', '赠送金额'),
            'start_time' => Yii::t('zhtfrontend', '开始时间'),
            'end_time' => Yii::t('zhtfrontend', '结束时间'),
            'number' => Yii::t('zhtfrontend', '活动人数'),
            'status' => Yii::t('zhtfrontend', '状态'),
            'created_at' => Yii::t('zhtfrontend', '创建时间'),
        ];
    }

    public function extraFields()
    {
        return [
            'operate' => function () {
                return (new MenuManage(MenuManage::RECORD_ITEM_TOOLBAR, $this->attributes))->create();
            },
        ];
    }

    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
                ],
            ],

        ]);
    }
}
